using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using Rhino.Mocks;

namespace GettingStartedWithRhinoMocks
{
    public class FamousPeople
    {
        public string Name { get; set; }
    }

    public interface IFamousPeopleRepository
    {
        IEnumerable<FamousPeople> GetFamousPeople();
    }

    public class FamousPeopleService
    {
        private readonly IFamousPeopleRepository _famousPeopleRepository;

        public FamousPeopleService(IFamousPeopleRepository famousPeopleRepository)
        {
            _famousPeopleRepository = famousPeopleRepository;
        }

        public IEnumerable<FamousPeople> NameStartsWithFilter(string searchText)
        {
            return _famousPeopleRepository.GetFamousPeople().Where(c => c.Name.StartsWith(searchText));
        }
    }

    [TestFixture]
    public class FamousPeopleServiceTestFixture
    {
        [Test]
        public void Can_Filter_FamousPeople_Using_Stub_To_Return_FamousPeople()
        {
            // Arrange
            var famousPeopleRepository = MockRepository.GenerateStub<IFamousPeopleRepository>();
            var famousPeopleService = new FamousPeopleService(famousPeopleRepository);

            famousPeopleRepository.Stub(c => c.GetFamousPeople()).Return(FamousPeopleStub);

            // Act
            var result = famousPeopleService.NameStartsWithFilter("Bill");

            // Assert
            Assert.That(result.Count(), Is.EqualTo(3));
        }

        private List<FamousPeople> FamousPeopleStub
        {
            get
            {

                return new List<FamousPeople>()
                           {
                               new FamousPeople(){Name = "Bill Gates"}   ,
                               new FamousPeople(){Name = "Bill Clinton"}   ,
                               new FamousPeople(){Name = "Bob Hope"}   ,
                               new FamousPeople(){Name = "Billy The Kid"}
                           };
            }
        }
    }
}